#region Using

using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using BlogEngine.Core;
using BlogEngine.Core.Web.Controls;

#endregion

public partial class gallery : BlogEngine.Core.Web.Controls.BlogBasePage
{
	public Album Album;

	protected void Page_Init(object sender, EventArgs e)
	{
		//	Response.Redirect(Utils.RelativeWebRoot + "error404.aspx", true);

		string path = "~/themes/" + BlogSettings.Instance.Theme + "/GalleryView.ascx";

		GalleryView galleryView = (GalleryView)LoadControl(path);
		galleryView.Album = Album;
		galleryView.Location = ServingLocation.SinglePost;

		pwGallery.Controls.Add(galleryView);

		int page = GetPageIndex();
		string url = "~/gallery.aspx?page={0}";

		hlNext.HRef = string.Format(url, page + 1);
		hlPrev.HRef = string.Format(url, page - 1);

		if (page == 1)
			hlPrev.Visible = false;
		else
			(Page as BlogBasePage).AddGenericLink("prev", "Previous page", hlPrev.HRef);

		if (hlNext.Visible)
			(Page as BlogBasePage).AddGenericLink("next", "Next page", hlNext.HRef);

	}

	/// <summary>
	/// Retrieves the current page index based on the QueryString.
	/// </summary>
	private int GetPageIndex()
	{
		int index = 0;
		if (!int.TryParse(Request.QueryString["page"], out index))
			return 1;

		if (index == 0)
			return 1;

		return index;
	}


}
